package com.cskaoyan._02method._03methodcases;

import java.util.Scanner;

/**
 * @author Macro_Ray
 * @since 2024/3/5 19:40
 */
/* 在唱歌比赛中，有6名评委给选手打分，分数范围是[0-100]之间的整数。
 * 选手的最后得分为:去掉最高分、最低分后的4个评委的平均分，
 * 请完成上述过程并计算出选手的得分。*/
public class _01Test_05 {
    public static void main(String[] args) {

        int[] scores = getScore();
        int sum = getSum(scores);
        int max = getMax(scores);
        int min = getMin(scores);
        double average = getAverage(sum, max, min);
        System.out.println("选手最终得分：" + average);
    }

    // 1.定义一个数组，输入6名评委的分数
    public static int[] getScore() {
        int[] scores = new int[6];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < scores.length; ) {
            System.out.println("请输入第" + (i + 1) + "位评委的打分");
            int score = sc.nextInt();
            if (score >= 0 && score <= 100) {
                scores[i] = score;
                i++;
            } else {
                System.out.println("请重新输入0-100之间的整数");
            }
        }
        return scores;
    }

    // 2.找到最高、最低分
    public static int getMax(int[] scores) {
        int max = 0;
        // 增强for循环，表示
        for (int score : scores) {
            if (score > max) {
                max = score;
            }
        }
        return max;
    }

    public static int getMin(int[] scores) {
        int min = 100;
        for (int score : scores) {
            if (score < min) {
                min = score;
            }
        }
        return min;
    }

    // 3.求6个总分
    public static int getSum(int[] scores) {
        int sum = 0;
        for (int score : scores) {
            sum += score;
        }
        return sum;
    }

    // 4.去掉最高分最低分求最后分数
    public static double getAverage(int sum, int max, int min) {
        double average = 0;
        average = (double) (sum - max - min) / 4;
        return average;
    }


}



/*// 1.定义一个数组，输入6名评委的分数
        int[] totalScore = new int[6];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < totalScore.length; i++) {
            for (; ; ) {
                System.out.println("请输入第" + (i + 1) + "位评委的打分");
                int score = sc.nextInt();
                if (score >= 0 && score <= 100) {
                    totalScore[i] = score;
                    break;
                }
                System.out.println("请重新输入0-100之间的整数");
            }
        }
        // 2.找到最高最低分
        int max = 0;
        int min = 100;
        for (int i = 0; i < totalScore.length; i++) {
            if (totalScore[i] > max)
                max = totalScore[i];
        }
        for (int i = 0; i < totalScore.length; i++) {
            if (totalScore[i] < min)
                min = totalScore[i];
        }
        // 3.求6个总分
        int sum = 0;
        for (int i = 0; i < totalScore.length; i++) {
            sum += totalScore[i];
        }
        // 4.（总分-最高分-最低分）/4
        double average = 0;
        average = (sum - max - min) / 4;
        System.out.println("最终选手得分是：" + average);*/